}
static int
-xc_ia64_pv_send_context(int xc_handle, int io_fd, uint32_t dom,
- shared_info_t *live_shinfo)
+xc_ia64_send_vcpumap(int xc_handle, int io_fd, uint32_t dom,
+ const xc_dominfo_t *info, uint64_t max_virt_cpus,
+ uint64_t **vcpumapp)
{
- /* A copy of the CPU context of the guest. */
- vcpu_guest_context_t ctxt;
- char *mem;
+ int rc = -1;
+ unsigned int i;
+ unsigned long vcpumap_size;
+ uint64_t *vcpumap = NULL;
- if (xc_ia64_send_vcpu_context(xc_handle, io_fd, dom, 0, &ctxt))
- return -1;
+ vcpumap_size = (max_virt_cpus + 1 + sizeof(vcpumap[0]) - 1) /
+ sizeof(vcpumap[0]);
+ vcpumap = malloc(vcpumap_size);
+ if (vcpumap == NULL) {
+ ERROR("memory alloc for vcpumap");
+ goto out;
+ }
+ memset(vcpumap, 0, vcpumap_size);
- mem = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
- PROT_READ|PROT_WRITE, ctxt.privregs_pfn);
- if (mem == NULL) {
- ERROR("cannot map privreg page");
- return -1;
+ for (i = 0; i <= info->max_vcpu_id; i++) {
+ xc_vcpuinfo_t vinfo;
+ if ((xc_vcpu_getinfo(xc_handle, dom, i, &vinfo) == 0) && vinfo.online)
+ __set_bit(i, vcpumap);
}
- if (write_exact(io_fd, mem, PAGE_SIZE)) {
- ERROR("Error when writing privreg to state file (5)");
- munmap(mem, PAGE_SIZE);
- return -1;
+
+ if (write_exact(io_fd, &max_virt_cpus, sizeof(max_virt_cpus))) {
+ ERROR("write max_virt_cpus");
+ goto out;
}
- munmap(mem, PAGE_SIZE);
- if (xc_ia64_send_shared_info(xc_handle, io_fd, live_shinfo))
- return -1;
+ if (write_exact(io_fd, vcpumap, vcpumap_size)) {
+ ERROR("write vcpumap");
+ goto out;
+ }
- return 0;
+ rc = 0;
+
+ out:
+ if (rc != 0 && vcpumap != NULL) {
+ free(vcpumap);
+ vcpumap = NULL;
+ }
+ *vcpumapp = vcpumap;
+ return rc;
+}
+
+
+static int
+xc_ia64_pv_send_context(int xc_handle, int io_fd, uint32_t dom,
+ const xc_dominfo_t *info, shared_info_t *live_shinfo)
+{
+ int rc = -1;
+ unsigned int i;
+
+ /* vcpu map */
+ uint64_t *vcpumap = NULL;
+ if (xc_ia64_send_vcpumap(xc_handle, io_fd, dom, info, MAX_VIRT_CPUS,
+ &vcpumap))
+ goto out;
+
+ /* vcpu context */
+ for (i = 0; i <= info->max_vcpu_id; i++) {
+ /* A copy of the CPU context of the guest. */
+ vcpu_guest_context_t ctxt;
+ char *mem;
+
+ if (!__test_bit(i, vcpumap))
+ continue;
+
+ if (xc_ia64_send_vcpu_context(xc_handle, io_fd, dom, i, &ctxt))
+ goto out;
+
+ mem = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
+ PROT_READ|PROT_WRITE, ctxt.privregs_pfn);
+ if (mem == NULL) {
+ ERROR("cannot map privreg page");
+ goto out;
+ }
+ if (write_exact(io_fd, mem, PAGE_SIZE)) {
+ ERROR("Error when writing privreg to state file (5)");
+ munmap(mem, PAGE_SIZE);
+ goto out;
+ }
+ munmap(mem, PAGE_SIZE);
+ }
+
+ rc = xc_ia64_send_shared_info(xc_handle, io_fd, live_shinfo);
+
+ out:
+ if (vcpumap != NULL)
+ free(vcpumap);
+ return rc;
}
static int
unsigned int i;
/* vcpu map */
- uint64_t max_virt_cpus;
- unsigned long vcpumap_size;
uint64_t *vcpumap = NULL;
/* HVM: magic frames for ioreqs and xenstore comms */
return -1;
/* vcpu map */
- max_virt_cpus = MAX_VIRT_CPUS;
- vcpumap_size = (max_virt_cpus + 1 + sizeof(vcpumap[0]) - 1) /
- sizeof(vcpumap[0]);
- vcpumap = malloc(vcpumap_size);
- if (vcpumap == NULL) {
- ERROR("memory alloc for vcpumap");
- goto out;
- }
- memset(vcpumap, 0, vcpumap_size);
-
- for (i = 0; i <= info->max_vcpu_id; i++) {
- xc_vcpuinfo_t vinfo;
- if ((xc_vcpu_getinfo(xc_handle, dom, i, &vinfo) == 0) && vinfo.online)
- __set_bit(i, vcpumap);
- }
-
- if (write_exact(io_fd, &max_virt_cpus, sizeof(max_virt_cpus))) {
- ERROR("write max_virt_cpus");
+ if (xc_ia64_send_vcpumap(xc_handle, io_fd, dom, info, MAX_VIRT_CPUS,
+ &vcpumap))
goto out;
- }
-
- if (write_exact(io_fd, vcpumap, vcpumap_size)) {
- ERROR("write vcpumap");
- goto out;
- }
/* vcpu context */
for (i = 0; i <= info->max_vcpu_id; i++) {
if (xc_ia64_send_vcpu_context(xc_handle, io_fd, dom, i, &ctxt))
goto out;
- // system context of vcpu is sent as hvm context.
+ /* system context of vcpu is sent as hvm context. */
}
/* Save magic-page locations. */
goto out;
if (!hvm)
- rc = xc_ia64_pv_send_context(xc_handle, io_fd, dom, live_shinfo);
+ rc = xc_ia64_pv_send_context(xc_handle, io_fd,
+ dom, &info, live_shinfo);
else
rc = xc_ia64_hvm_send_context(xc_handle, io_fd,
dom, &info, live_shinfo);